#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "galois_add.h"
#include "galois.h"

main (int argc, char **argv)
{
	uint64_t a, q1, q2;
	uint64_t n, s, t;
	uint64_t i;
	uint64_t one;
	uint64_t num_tests;
	uint64_t top;
	int good;
	int failed;

	if (argc != 2) { fprintf(stderr, "usage: prog num_tests\n"); exit(1); }

	n = 32;
	one = 1;
	top = (one << (n/4)) - 1;
	num_tests = atoi(argv[1]);

	srand48(0);
	good = 1;
	for (i = 0; i < num_tests; i++) {
		a = lrand48();
		a <<= 32;
		a += lrand48();
		a = a % ((one << n) - 1);

		q1 = galois_composite_inverse_k4(a, n);
		q2 = galois_composite_multiply_k4(q1, a, n);

		if (q2 != 1 && a != 0) {
			printf("%lu\n", a);
			good = 0;
		}
	}
	if (good) {
		printf("Success!\n");
	}
}
